package com.example.aicooking.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.aicooking.entity.User;
import com.example.aicooking.entity.vo.UserBasicVO;
import com.example.aicooking.entity.vo.UserDetailVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("SELECT * FROM user WHERE user_name LIKE CONCAT('%', #{keyword}, '%')")
    List<User> searchByUsername(@Param("keyword") String keyword);

    @Update("UPDATE user SET last_login_time = #{lastLoginTime} WHERE user_id = #{userId}")
    int updateLastLoginTime(User user);

    @Insert("INSERT INTO user (user_id, user_name, password, gender, age, create_time) " +
            "VALUES (#{userId},#{userName}, #{password}, #{gender}, #{age}, #{createTime})")
    @Options(useGeneratedKeys = true, keyProperty = "userId")
    int insert(User user);

    @Select("SELECT * FROM user WHERE user_id = #{userId}")
    User findByUserId(Integer userId);

    /**
     * 个人页面展示
     * 昵称，头像，个性签名
     * */
    @Select("select user_id, nickname, avatar, signature from user where user_id = #{userId}")
    UserBasicVO getBasicInfo(Integer userId);

    /*
    * 个人信息页面
    * */
    @Select("select user_id, user_name, gender, age, avatar, phone, create_time, " +
            "last_login_time, nickname, signature from user where user_id = #{userId}")
    UserDetailVO getDetailInfo(Long userId);


}